package com.longrise.android.byjk.plugins.tabfirst.allfunction;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.common.base.BaseActivity;
import com.longrise.android.byjk.R;
import com.longrise.android.byjk.event.HomeJumpLfEvent;
import com.longrise.android.byjk.plugins.tabfirst.CustomerModuleJumpHelper;
import com.longrise.android.byjk.utils.Tracker_Google;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by callxkj on 2017/3/8.
 * 全部功能界面
 */

public class AllFunctionActivity extends BaseActivity<AllFunctionPresenter> implements AllFunctionContract.View {

    private Toolbar mToolbar;
    private RecyclerView mRcv;
    private AllFunctionRcvAdapter mRcvAdapter;
    private TextView mTvTitle;

    @Override
    public int getContentViewId(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_allfunction;
    }


    @Override
    public void initView() {
        mToolbar = (Toolbar) findViewById(R.id.byjk_toolbar);
        mToolbar.setTitle("");
        setSupportActionBar(mToolbar);
        mTvTitle = (TextView) findViewById(R.id.bb_toolbar_middle_title);
        mRcv = (RecyclerView) findViewById(R.id.allfunction_rcv);
        mRcvAdapter = new AllFunctionRcvAdapter();
        mRcv.setLayoutManager(new LinearLayoutManager(mContext));
        initHead();
        mRcv.setAdapter(mRcvAdapter);
        initData();
        initEvent();
        Tracker_Google.getInstance().addGoogleScreenName("全部功能");
    }

    private void initHead() {
        View view = View.inflate(mContext, R.layout.head_allfunction_rcv, null);
        mRcvAdapter.addHeaderView(view);
    }

    private void initData() {

        mTvTitle.setVisibility(View.VISIBLE);
        mTvTitle.setText("全部功能");
    }

    private void initEvent() {
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mRcvAdapter.setOnAllFunctionItemClickListener(new AllFunctionRcvAdapter.OnAllFunctionItemClickListener() {
            @Override
            public void onClick(String uniqueid, String linkedtype, String showname, String linkedurl, String fullurl) {
                if ("1001".equals(uniqueid)) {//我的课程
                    finish();
                    EventBus.getDefault().post(new HomeJumpLfEvent(HomeJumpLfEvent.WDKC));
                } else if ("1002".equals(uniqueid)) { //培训报名
                    finish();
                    EventBus.getDefault().post(new HomeJumpLfEvent(HomeJumpLfEvent.PXBM));
                } else if ("1010".equals(uniqueid)) { //每日一练
                    finish();
                    EventBus.getDefault().post(new HomeJumpLfEvent(HomeJumpLfEvent.MRYL));
                }else{
                    CustomerModuleJumpHelper.toJump(mContext, uniqueid, linkedtype, showname, linkedurl, fullurl, null);
                }
                addGoogleEvent(uniqueid, showname);
            }
        });
    }


    @Override
    public void showToast(String msg) {

    }

    @Override
    public void refreshData(EntityBean[] beans) {
        mRcvAdapter.setData(beans);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    private void addGoogleEvent(String uniqueid, String text) {
        if (!TextUtils.isEmpty(uniqueid)) {
            addGoogleEvent("all-functions", uniqueid, text);
        }
    }

    private void addGoogleEvent(String par1, String par2, String par3) {
        Tracker_Google.getInstance().addEvent(par1, par2, par3);
    }

}
